<?php

require_once 'Zend/View/Helper/Abstract.php';

class Core_View_Helper_Internationalization_GetTranslation extends Zend_View_Helper_Abstract
{
    /**
     * Returns the translation for the passed key,
     *
     * @return  string
     */
    public function getTranslation($key, $locale = null, $viewInstance = null)
    {
        if ($viewInstance !== null) {
            $this->setview($viewInstance);
        }
        $adapter         = Zend_Registry::get('Zend_Translate');
        $moduleName      = $this->view->getRequest()->getModuleName();
        $currentLanguage = $this->view->getCurrentLanguage();
        if ($locale != null) {
            $this->view->translate()->setLocale($locale);
        } else if ($moduleName != 'admin' && $adapter->isAvailable($currentLanguage)) {
            $this->view->translate()->setLocale($currentLanguage);
        }
        return $this->view->translate($key);
    }
}